
package melwi;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Kreslitko extends JFrame implements WindowListener, ActionListener {
	
	public Kreslitko(String nadpis, Hmat[] akord) {
		super(nadpis); //dodelat nadpis, nejlepe dle akordu
		

		int sirka=950;
		int vyska=550;
		this.setSize(sirka,vyska);
		
		this.addWindowListener(this);
		//sp.setSize(150, 50);
		//sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		this.setVisible(true);

		Platno canvas=new Platno(akord);
		JScrollPane sp = new JScrollPane(canvas);
//		JScrollPane sp = new JScrollPane();
		//sp.setViewportView(canvas);
		//setContentPane(sp);
		this.add(sp);
//		this.pack();
	}

//proc jsou tu ty tridy vnorene? zavorky tak jak jsou?




class Platno extends JPanel{
	private Hmat[] akord;
	public Platno(Hmat[] akordT){
		super();
		this.akord = akordT;


		int poc=akord.length; //testovaci
		int fretPaint=5; //kolik bude nakreslenych prazcu
		int pocetMax=10; //kolik akordu se vejde vedle sebe na stranku
		int s=12;  //x vzdalenost mezi strunami
		int m=30; //x vzdalenost mezi jednotlivymi akordy
		int p=18; //y vzdalenost mezi prazci
		int n=18; //y vzdalenost mezi jednotlivymi akordy

		int vyska=((poc/pocetMax)+1)*(4*p+n)+n;
		int sirka=pocetMax*(5*s+m)+m;
		Dimension dim=new Dimension(sirka, vyska);
		this.setPreferredSize(dim);
	

	}
	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		int poc=akord.length; //testovaci
		int fretPaint=5; //kolik bude nakreslenych prazcu
		int pocetMax=10; //kolik akordu se vejde vedle sebe na stranku
		int s=12;  //x vzdalenost mezi strunami
		int m=30; //x vzdalenost mezi jednotlivymi akordy
		int p=18; //y vzdalenost mezi prazci
		int n=18; //y vzdalenost mezi jednotlivymi akordy

		int vyska=((poc/pocetMax)+1)*(4*p+n)+n;
		int sirka=pocetMax*(5*s+m)+m;
	        // g.drawOval(10,10,100,50); /*x. y souradnice leveho horniho rohu
		//int Nastroj.stringNum=6; //testovaci!!!!!!!!!
		//int poloha[]={3,4,3,5,0,2};
		//int min=2;
		int r=4;

		for(int i=0; i<poc; i++){
			int radek=i/pocetMax+1; //na jakem jsme sloupci a radku
			int sloupec=i%pocetMax+1; 
			
//			System.out.println(sloupec+" " + radek); //kontrola sloupcu a radku
			int x=m+(5*s+m)*(sloupec-1); //vypocet leveho horniho rozku, jeho x a y souradnice
			int y=n+(4*p+n)*(radek-1);
			
			for(int j=0; j<Nastroj.stringNum; j++){
				g.drawLine(x+j*s,y,x+j*s,y+4*p);
			}
			for(int k=0; k<fretPaint; k++){
				g.drawLine(x,y+k*p,x+5*s,y+k*p); //!!!zobecnit ty hodnoty!!!! konkretni cisla sem nepatri!
			}
			int[] poloha = akord[i].getPoloha();
			int min = akord[i].getMin();
			g.drawString(String.valueOf(min),x+5*s+5, y+p); //dat dal!!!!!
//!!!!!!!!!!!!!!!!!!dodelat


			for(int l=0;l<Nastroj.stringNum;l++){
				//g.setColor(Color.green);
				
				if(poloha[l]!=0){	
					g.fillOval(x+l*s-r, y+(poloha[l]-min)*p+(p/2)-r, 2*r, 2*r);
				}
	//			System.out.println((x+l*s-r) + " " + (y+(poloha[l]-min)*p+(p/2)-r)); 
				//x+l-r //x poloha
				//y+poloha[l]-min+(p/2)+r; //y poloha
				
			}
			//kresleni kolecek

		}

		
        }
	
}
	


	public void windowActivated(java.awt.event.WindowEvent windowEvent) {
	}
	public void windowClosed(java.awt.event.WindowEvent windowEvent) {
	System.exit(0);
	}
	public void windowClosing(java.awt.event.WindowEvent windowEvent) {
		this.dispose();
	}
	public void windowDeactivated(java.awt.event.WindowEvent windowEvent) {
	}
	public void windowDeiconified(java.awt.event.WindowEvent windowEvent) {
	}
	public void windowIconified(java.awt.event.WindowEvent windowEvent) {
	}
	public void windowOpened(java.awt.event.WindowEvent windowEvent) {
	}
	public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
	}


}
